package com.burpee.dao;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Food;

@Repository(value="foodDao")
public class FoodDaoImpl implements FoodDao {

	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}


	public List<Food> list(HashMap<String, String> foodchoice) {
		List<Food> list = null;

		try {
			list = sqlSessionTemplate.selectList("foodList",foodchoice);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public Food view(long foodNo) {
		Food food = new Food();

		try {
			food = sqlSessionTemplate.selectOne("foodview", foodNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return food;
	}

	public int add(Food food) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("foodAdd",food);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(Food food) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("foodmodify",food);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}



	public List<Food> foodIngestPurposeSelectList(Food food) {
		// TODO Auto-generated method stub
		List<Food>list = null;

		try {
			list = sqlSessionTemplate.selectList("foodIngestPurposeSelectList",food);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	public List<Food> foodClassList() {
		List<Food>list = null;
		try {
			list = sqlSessionTemplate.selectList("foodClassList");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	public List<Food> foodClassficationList(){
		List<Food>list = null;
		try {
			list = sqlSessionTemplate.selectList("foodClassficationList");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}


	public int adminfoodCount() {
		
		int result = 0;
		
		result = sqlSessionTemplate.selectOne("adminfoodCount");
		
		return result;
	}


	public List<Food> adminfoodList(int currentPage) {
		List<Food> list = null;
		
		list = sqlSessionTemplate.selectList("adminfoodList", currentPage);
		
		return list;
	}
	
	
	public int adminFoodremove(String foodNo) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("adminfoodRemove", foodNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}


	public int adminFoodremoveCancel(String foodNo) {
		
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("adminfoodRemoveCancel", foodNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}
	
	
	

}
